package org.zn.plus.mybatis.sql.builder.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * @author 周楠
 * @version V1.0
 *
 *
 * 2020年6月28日
 */
public class QueryTable implements Fragment{
	
	public static final String clazz="queryTable";
	
	private	String tableName;
	
	private	String alias=StringUtils.EMPTY;	
	
	private List<SelectColumn> selectColumns;
	
	private List<WhereColumn> whereColumns;
	
	private  List<QueryOrder> orders;
	
	private  List<String> groupBys;
	
	// 预留 暂不使用 ，使用 queryStatment 中的
	private  List<JoinTable> joinTables;
	
	@SuppressWarnings("unchecked")
	public QueryTable() {
		this.orders=Collections.EMPTY_LIST;
		this.groupBys=Collections.EMPTY_LIST;
		this.joinTables=Collections.EMPTY_LIST;
		this.whereColumns=Collections.EMPTY_LIST;
		this.selectColumns=Collections.EMPTY_LIST;
	}
	

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getAlias() {
		return alias.equals(StringUtils.EMPTY)?tableName:alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public List<SelectColumn> getSelectColumns() {
		return this.selectColumns;
	}

	public void setSelectColumns(List<SelectColumn> selectColumns) {
		this.selectColumns = selectColumns;
	}
	
	public void addSelectColumns(SelectColumn selectColumn) {
		
		if(selectColumns==null||selectColumns.equals(Collections.EMPTY_LIST)) selectColumns=new ArrayList<>();
		
		selectColumns.add(selectColumn);
	}
	

	public List<WhereColumn> getWhereColumns() {
		return whereColumns;
	}

	public void setWhereColumns(List<WhereColumn> whereColumns) {
		this.whereColumns = whereColumns;
	}
	
	public void addWhereColumns(WhereColumn whereColumn) {
		
		if(whereColumns==null||whereColumns.equals(Collections.EMPTY_LIST)) whereColumns=new ArrayList<>();
		
		whereColumns.add(whereColumn);
	}

	public List<QueryOrder> getOrders() {
		return orders;
	}

	public void setOrders(List<QueryOrder> orders) {
		this.orders = orders;
	}
	
	public void addOrders(QueryOrder order) {
	
		if(orders==null||orders.equals(Collections.EMPTY_LIST)) orders=new ArrayList<>();
		
		this.orders.add(order);
	}
	
	
	

	public List<String> getGroupBys() {
		return groupBys;
	}

	public void setGroupBys(List<String> groupBys) {
		this.groupBys = groupBys;
	}
	
	public void addGroupBys(String groupBy) {

		if(groupBys==null||groupBys.equals(Collections.EMPTY_LIST)) groupBys=new ArrayList<>();
		
		this.groupBys.add(groupBy);
		
	}


	public List<JoinTable> getJoinTables() {
		return joinTables;
	}


	public void setJoinTables(List<JoinTable> joinTables) {
		this.joinTables = joinTables;
	}
	
	public void addJoinTables(JoinTable joinTable) {
		if(this.joinTables==Collections.EMPTY_LIST)  joinTables=new ArrayList<>();
		joinTables.add(joinTable);
	}
	
	@Override
	public Fragment self() {
		// TODO Auto-generated method stub
		return this;
	}
	
	
}
